package com.srlg.batch.controller;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class JobLauncherController {

    private final JobLauncher jobLauncher;

    private final Job importUserJob;

    private final Job delFileJob;

    @GetMapping("handle")
    @SneakyThrows
    public String handle() {

        jobLauncher.run(importUserJob, new JobParameters());

        return "success";
    }

    @GetMapping("delFile")
    @SneakyThrows
    public String delFile() {

        jobLauncher.run(delFileJob, new JobParameters());

        return "success";
    }
}
